﻿ 
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using Microsoft.ApplicationBlocks.Data; 
using NTTDATA.BEENChina.ResultCertification.model;

namespace NTTDATA.BEENChina.ResultCertification.DataStore
{
    public class JaTextClientAccess:IJaTextClientAccess
    {

        private static string ConnectionString
        {
            get
            {
                return System.Configuration.ConfigurationManager.AppSettings["ResultCertificationDB"];
            }
        }

        
       public List<JaTextItem> GetJaText(Config.EnumTextType textType)
       {
           string sql = "SELECT [ID],[Name],[maxSimilarity],[NameType] FROM [JaText] WHERE [NameType] = @NameType ";

           SqlParameter[] sqlParameters = 
                {
                    new SqlParameter("@NameType",  textType.ToString())
                };


           List<JaTextItem> textItems = null;
           try
           {
               using (
                   SqlDataReader reader = SqlHelper.ExecuteReader(ConnectionString, System.Data.CommandType.Text, sql,sqlParameters))
               {
                   while (reader.Read())
                   {
                       if (textItems == null)
                           textItems = new List<JaTextItem>();


                       textItems.Add(new JaTextItem()
                       {
                           ID = reader.GetString(0),
                           Name = reader.GetString(1),
                           MaxSimilarity = reader.GetDecimal(2),
                           NameType = textType
                       });
                   }

                   reader.Close();
               }
           }
           catch (Exception ex)
           {
               Log.Console.Error("JaTextClientAccess.GetJaText", ex);
           }

           return textItems;
       }
    }
}
